<template>
  <div>
    <basic-container>
      <!-- START goBack -->
      <div class="el-page-header haruyuki-mb-20">
        <div class="haruyuki-page-header-left haruyuki-size-18" @click="goBack">
          <i class="el-icon-arrow-left"></i>
          <div class="haruyuki-size-24">返回</div>
        </div>
      </div>
      <!-- END goBack -->
      <div
        class="el-page-header__content"
        style="text-align: center; font-size: 30px; padding-bottom: 20px"
      >
        商品订单详情
      </div>

      <section class="haruyuki-bg-color-white">
        <div class="haruyuki-flex-space-between haruyuki-align-items-center">
          <div class="haruyuki-content">
            <el-row :gutter="20" style="font-size: 18px">
              <el-col :span="24">
                <span>订单总金额：{{ basicData.shopPriceTotal }}</span>
              </el-col>
              <el-col :span="12">
                <span>订单编号：{{ basicData.shopOrderNo }}</span>
              </el-col>
              <el-col :span="12">
                <span>交易流水号：{{ basicData.shopSerialNo }}</span>
              </el-col>
              <el-col :span="12">
                <span>产品分类：{{ basicData.shopClassName }}</span>
              </el-col>
              <el-col :span="12">
                <span>产品类型：{{ basicData.shopTypeName }}</span>
              </el-col>
              <el-col :span="12">
                <span>产品型号：{{ basicData.shopModelName }}</span>
              </el-col>

              <el-col :span="12">
                <span>服务商编号：{{ basicData.serviceNo }}</span>
              </el-col>
              <el-col :span="12">
                <span>服务商名称：{{ basicData.serviceName }}</span>
              </el-col>
              <el-col :span="24">
                <span>收货人：{{ basicData.shopConsignee }}</span>
                <el-tooltip class="item" effect="dark" content="点击复制收货地址" placement="top"  v-if="basicData.shopConsignee">
                  <i class="el-icon-document-copy" style="margin-left:20px;cursor: pointer;" @click="clickCopy(basicData)" ></i>
                </el-tooltip>
              </el-col>
              <el-col :span="24">
                <span>收货人联系方式：{{ basicData.shopConsigneePhone }}</span>
              </el-col>
              <el-col :span="24">
                <span>省/市/区：{{ basicData.areaString }}</span>
              </el-col>
              <el-col :span="24">
                <span
                  >配送方式：{{
                    basicData.shopDeliveryMethod == "1"
                      ? "上门自提"
                      : "物流快递"
                  }}</span
                >
              </el-col>
              <el-col :span="24">
                <span>收货地址：{{ basicData.shopConsigneeAddress }}</span>
              </el-col>
              <el-col :span="24">
                <span>备注内容：{{ basicData.shopRemarks }}</span>
              </el-col>
            </el-row>
          </div>
        </div>
        <div class="btnWrap">
          <el-button
            style="width: 120px; height: 50px"
            type="primary"
            @click="goBack()"
            >返回</el-button
          >
          <el-button
            style="width: 120px; height: 50px; margin-left: 20px"
            type="primary"
            v-if="
              (this.basicData.shopOrderStatus == '1' ||
                this.basicData.shopOrderStatus == '2') &&
              this.basicData.shopRefundStatus == ''
            "
            @click="handleRefund()"
            >退款</el-button
          >
        </div>
      </section>
    </basic-container>
  </div>
</template>

<script>
import { getDetailById } from "@/api/rb-oem/shopOrder/shop_order";
import { addRefund } from "@/api/rb-oem/shopRefund/shop_refund";

import { mapGetters } from "vuex";
import basicForm from "@/components/rb-service/basic-form";

export default {
  components: {
    basicForm,
  },
  data() {
    return {
      labelData: {
        basicTitle: "订单详情",
      },
      shopOrderId: this.$route.query.id,
      dialogVisible: false,
      passVisible: false,
      dialogText: "",
      active: 0,
      policyVisible: false,
      service: {},
      basicData: {
        shopOrderNo: "",
        shopSerialNo: "",
        shopClassName: "",
        shopTypeName: "",
        shopModelName: "",
        shopPriceTotal: "",
        shopLogisticsNo: "",
        shopDeliveryMethod: "",
        shopLogisticsCompany: "",
        areaString: "",
        serviceNo: "",
        serviceName: "",
        shopConsignee: "",
        shopConsigneePhone: "",
        shopConsigneeAddress: "",
        shopOrderStatus: "",
        shopRefundStatus: "",
        shopRemarks: "",
      }
    };
  },
  computed: {
    ...mapGetters(["permission"]),
    permissionList() {
      return {
        addBtn: this.vaildData(this.permission.shop_order_add, false),
        viewBtn: this.vaildData(this.permission.shop_order_view, false),
        delBtn: this.vaildData(this.permission.shop_order_delete, false),
        editBtn: this.vaildData(this.permission.shop_order_edit, false),
      };
    },
    ids() {
      let ids = [];
      this.selectionList.forEach((ele) => {
        ids.push(ele.id);
      });
      return ids.join(",");
    },
    exhibition() {
      return (val) => {
        if (val == "" || val == "-1") {
          return (val = 0);
        } else {
          return val;
        }
      };
    },
    getYearMonth() {
      return (date) => {
        let result = (date + "").split(" ");
        return result[0];
      };
    }
  },
  created() {
    this.infoData(this.shopOrderId);
  },
  methods: {
    // 复制
    clickCopy(basicData) {
      // ht 字符串 | ht格式别乱动
      let ht = `${basicData.shopConsignee}
${basicData.shopConsigneePhone}
${basicData.areaString}
${basicData.shopConsigneeAddress}`;
      const save = function (e) {
        e.clipboardData.setData("text/plain", ht);
        e.preventDefault(); // 阻止默认行为
      };
      const once = {
        once: true,
      };
      document.addEventListener("copy", save, once); // 添加一个copy事件
      document.execCommand("copy"); // 执行copy方法
      this.$message({ message: "复制成功", type: "success" });
    },
    /* 返回页面 */
    goBack() {
      this.$router.$avueRouter.closeTag();
      this.$router.back();
    },
    /* 页面加载 初始化请求详情接口 */
    infoData(id) {
      getDetailById(id).then((res) => {
        this.basicData = res.data.data;
      });
    },
    /* 退款提交处理 */
    handleRefund() {
      if (
        this.basicData.shopRefundStatus != null &&
        this.basicData.shopRefundStatus != ""
      ) {
        this.$confirm("已退款，请勿重复退款", "提示", {
          confirmButtonText: "确定",
          type: "warning",
        }).then(() => {
          this.goBack().then(() => {});
        });
      } else {
        this.$confirm("是否退款?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then(() => {
          addRefund(this.basicData).then((res) => {
            if (res.status == "200") {
              // this.infoData(this.shopOrderId);
              
              this.$root.Bus.$emit('orderDetail'); //传播方法

              this.$message({
                type: "success",
                message: "操作成功!",
              });
            } else {
              this.$message({
                type: "error",
                message: res.data.message,
              });
            }
          });
          this.goBack().then(() => {});
        });
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.btnWrap {
  display: flex;
  justify-content: center;
  align-content: center;
}
/deep/.el-transfer-panel__list.is-filterable {
  width: 400px !important;
  height: 500px !important;
}

/deep/.el-transfer-panel {
  width: 400px !important;
  height: 500px !important;
}

.picture-preview {
  color: #409eff;
  cursor: pointer;
}

.haruyuki-image-preview {
  width: 260px;
}
.image-preview-title {
  // text-align: center;
  margin-bottom: 10px;
}
.haruyuki-image-preview .haruyuki-image .el-image {
  border-radius: 10px;
}

/deep/ .el-image__error {
  background: #fff;
}
.infoWrap_line {
  display: flex;
  align-items: center;
  padding-bottom: 30px;
  .info_line_span {
    width: 160px;
    text-align: right;
  }
}
.nullData {
  text-align: center;
  font-size: 24px;
  font-weight: bold;
}
.w100 {
  width: calc(100% - 160px);
}
.btnCode {
  width: 100px;
  border-radius: 0;
  padding: 0;
  margin: 10px 0;
  background: #409eff !important;
}
.btnCode:hover {
  padding: 0;
  border: none;
  background: #409eff !important;
}
/deep/ .el-input-group__append {
  background: #409eff !important;
  color: #fff !important;
  padding: 0;
}
</style>